const app = getApp()

Page({
    data: {

    },
    doRegist: function(e){
        var formObject = e.detail.value;
        var username = formObject.username;
        var password = formObject.password;
        var passwordCheck = formObject.passwordCheck;
        //简单验证
        if(password != passwordCheck){
            wx.showToast({
              title: '两次密码不一致！',
              icon: 'none',
              duration: 3000
            })
        }
        else if(username.length == 0 || password.length == 0){
            wx.showToast({
                title: '用户名或密码不能为空！',
                icon: "none",
                duration: 3000
            })
        }
        else{
            var serverUrl = app.serverUrl;
            wx.showLoading({
                title: '少女祈祷中...',
              }),
            wx.request({
                url: serverUrl + '/register.do' ,
                method: 'POST',
                data:{
                    username: username,
                    password: password
                },
                header:{
                    'content-type': 'application/json'
                },
                success: function(res){
                    wx.hideLoading();
                    console.log(res.data);
                    wx.showToast({
                      title: res.data.msg,
                      icon: "success",
                      duration: 3000
                    })
                    // app.userInfo = res.data.data;
                    //fixme 修改原有的全局对象为本地缓存
                    app.setGlobalUserInfo(res.data.data);
                    wx.redirectTo({
                      url: '../userLogin/login',
                    })
                }

            })
        }
    },
    goLoginPage:function(e){
        wx.navigateBack({
          delta: 0,
        })
    }
})